import { Readable, Transform } from "stream";
import { pipeline } from "node:stream/promises";

import { testFn } from "../utils/common";

function testPipe() {
  const readstream = Readable.from([
    [1, 200],
    [201, 500],
  ]);
  const transform = new Transform({
    objectMode: true,
    transform(chunk, encoding, callback) {
      console.log("🚀 ~ transform ~222 chunk:", chunk);
      this.push(chunk);
      callback();
    },
  });
  const pipePromise = pipeline(readstream, transform);

  pipePromise.then((data) => {
    console.log("🚀 ~ testPipe ~ data===========:", data);
  });
}

export default testFn(testPipe);
